package com.example.demo.controller;

import cn.hutool.captcha.CaptchaUtil;
import cn.hutool.captcha.LineCaptcha;
import com.example.demo.commom.AjaxResult;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.UUID;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User:龙宝
 * Date:2023-10-16
 * Time:14:49
 */
@RestController
//@RequestMapping("")
public class testController {

    @Value("${imagepath}")
    private String imagepath; // 验证码的本地路径

    @RequestMapping("/getCaptcha")
    public Object getCaptcha1(){
        // 1.生成验证码到本地
        //定义图形验证码的长和宽 (这个验证码的大小需要和自己前端的验证码的大小匹配)
        LineCaptcha lineCaptcha = CaptchaUtil.createLineCaptcha(128, 50);
        String uuid = UUID.randomUUID().toString().replace("-","");
        // 图形验证码写出，可以写出到文件，也可以写出到流
        lineCaptcha.write(imagepath + uuid + ".png");

        return AjaxResult.success(imagepath+uuid+".png");
    }

}
